package com.linwen.excise.leetcode;

import java.util.Objects;

/**
 * @ClassName _682棒球比赛
 * @Description TODO
 * @Author zero
 * @DATE 2024/9/28 5:39 PM
 * @Version 1.0
 */
public class _682棒球比赛 {
    public static void main(String[] args) {
        _682棒球比赛 inst = new _682棒球比赛();
        String[] ops = {"5","2","C","D","+"};
        System.out.println(inst.calPoints(ops));
    }
    public int calPoints(String[] operations) {
        int index = 0;
        int[] result = new int[operations.length+1];
        for (int i = 0; i < operations.length; i++) {
            if (Objects.equals(operations[i], "+")) {
                result[index] = result[index - 1] + result[index - 2];
                index++;
            } else if (Objects.equals(operations[i], "D")) {
                result[index] = result[index - 1] << 1;
                index++;
            } else if (Objects.equals(operations[i], "C")) {
                result[index - 1] = 0;
                index--;
            } else {
                result[index] = Integer.parseInt(operations[i]);
                index++;
            }
        }
        int count = 0;
        for (int i = index; i >= 0; i--) {
            count += result[i];
        }
        return count;
    }
}
